$.ajax({
    type: 'get',
    url: '/posts',
    success: function(response) {
        var html = template('postsTpl', { data: response.records });
        var html1 = template('pageTpl', response);
        $('#postsBox').html(html)
        $('#pageBox').html(html1)
    }
});


//分页的跳转
function changePage(page) {
    $.ajax({
        type: 'get',
        url: '/posts',
        data: {
            page
        },
        success: function(response) {
            var html = template('postsTpl', { data: response.records });
            var html1 = template('pageTpl', response);
            $('#postsBox').html(html)
            $('#pageBox').html(html1)
        }
    });
};
// 获取文章分类信息
$.ajax({
    type: 'get',
    url: '/categories',
    success: function(response) {
        var html = template('categoryTpl', { data: response });
        $('#categoryBox').html(html)
    }
});
// 根据分类获取文章列表
$('#screenOut').on('submit', function() {
    var formData = $(this).serialize()
    $.ajax({
        type: 'get',
        url: '/posts',
        data: formData,
        success: function(response) {
            var html = template('postsTpl', { data: response.records });
            var html1 = template('pageTpl', response);
            $('#postsBox').html(html)
            $('#pageBox').html(html1)
        }
    })
    return false;
});
//删除文章
$('#postsBox').on('click', '#delete', function() {
    var id = $(this).data('id')
    $.ajax({
        type: 'delete',
        url: '/posts/' + id,
        success: function() {
            location.reload()
        }
    })
})